// pages/signFail/signFail.js
import api from "../../config/api"
import request from "../../utils/request"
import { shareOptions } from "../../utils/access"
import { getBarAndTitleHeight, getXsScreen, stringify, getStorage, goBack, jump } from "../../utils/utils"

Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 用户信息
    userInfo: {},
    // 拍照结果信息
    taskData: {},
    // 累计分类天数
    classDays: 0,
    // 分类签到天数
    signDays: 0,
    // 信号栏高度
    ...getBarAndTitleHeight(),
    // 是否是小屏幕尺寸
		...getXsScreen(),
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserData()
    this.setData({
      taskData: options,
      signDays: +options?.signDays || 0
    })
  },
  // 获取用户信息
  async getUserData(){
    const userInfo = getStorage('userInfo')
    const res = await request.get(api.userDays)

    this.setData({
      userInfo,
      classDays: res?.data?.accumulatedClassifyDays,
      signDays: res?.data?.signInDays,
    })
  },
  // 跳转桶内详情
  goBucketAnalyse(){
    const { taskData } = this.data
    const { ingredient, bucketType, url } = taskData || {}

    jump('bucketAnalyse', {
      url,
      ingredient,
      bucketType,
      taskData: stringify(taskData || {})
    })
  },
  // 返回上一页
  back(){
    goBack()
  },
  // 重新签到
  restart() {
    goBack()
  },
  // 用户点击右上角分享
  onShareAppMessage(e) {
    return shareOptions('award', e)
	},
})